import App from './App'

// #ifndef VUE3
import Vue from 'vue'

Vue.config.productionTip = false
App.mpType = 'app'
import { tools } from './static/js/tools.js'
// import store from '@/store/index'
import { useLevel } from '@/utils/level'
import TuniaoUI from 'tuniao-ui'
import store from './store'
import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue"
import common from './utils/noClick.js'//节流
Vue.use(TuniaoUI)
Vue.component('ayQrcode', ayQrcode)
Vue.prototype.header = tools.header
Vue.prototype.show = tools.show
Vue.prototype.equal = tools.equal

Vue.prototype.$no = common.noMutClick;
let vuexStore = require('./store/$tn.mixin.js')
Vue.mixin(vuexStore)
// 引入自定义指令，用于显示指定的等级背景、
// uni-app不支持
// useLevel(Vue)
try {
  function isPromise(obj) {
    return (
      !!obj &&
      (typeof obj === 'object' || typeof obj === 'function') &&
      typeof obj.then === 'function'
    )
  }

  // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  uni.addInterceptor({
    returnValue(res) {
      if (!isPromise(res)) {
        return res
      }
      return new Promise((resolve, reject) => {
        res.then((res) => {
          if (res[0]) {
            reject(res[0])
          } else {
            resolve(res[1])
          }
        })
      })
    },
  })
} catch (error) {
}

const app = new Vue({
  store,
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'

export function createApp() {
  const app = createSSRApp(App)
  return {
    app,
  }
}

// #endif